﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JM.JCY.Proxy;
using JM.JCY.BusinessEntity;
using System.IO;
using JM.JCY.Common;
using System.Globalization;
using System.Data;

namespace JM.JCY.SharePointComponent.Speech.HomeSpeech
{
    public partial class HomeSpeechUserControl : UserControl
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindList();
            }
        }

        public string PartSubString(string fieldName, string fieldValue)
        {
            string returnVal = fieldValue;
            if (fieldName == "Subject" && fieldValue.Length > 50)
                returnVal = fieldValue.Substring(0, 50);
            else if (fieldName == "Summary" && fieldValue.Length > 100)
                returnVal = fieldValue.Substring(0, 100);
            return returnVal;
        }

        protected void BindList()
        {
            using (NewsProxy proxy = new NewsProxy())
            {
                NewsDataSet.T_AnnouncementDataTable SpeechDT = proxy.GetSpeechForHome(Int32.Parse(JCYConstant.DisplayCount));
                dlBCSpeech.DataSource = SpeechDT;
                dlBCSpeech.DataBind();
            }
        }

    
        protected void dlBC_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            // load date format
            Label lblEffDate = (Label)e.Item.FindControl("lblEffDateSpeech");

            string dateString = lblEffDate.Text;
            DateTime dateTime = DateTime.Parse(ConvertDateFormat(dateString));
            lblEffDate.Text = dateTime.ToString(JCYConstant.Date_Format_CN);
        }

        private string ConvertDateFormat(string date)
        {
            var str = date.Split('/');
            return str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
        }
    }
}
